package com.bjsxt.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ItearatorRremoveTest {
    public static void main(String[] args){
        List<String> list =new ArrayList<>();
        list.add("aa");
        list.add("bb");
        list.add("cc");
        for(int i =0;i<list.size();i++){
//            list.remove(2);  //错误的！
//            list.add("sd");  //错误！
            System.out.println(list.get(i));
        }
        for(String str:list){
//            list.add("sd");
            System.out.println(str);
        }

        Iterator<String> iterator = list.iterator(); //迭代器一次性
        while(iterator.hasNext()){
            String v= iterator.next();
            System.out.println(v);
        }
        for (Iterator<String> it =list.iterator();it.hasNext();){
            System.out.println(it.next());
        }
    }
}
